<template>
  <page-header-wrapper>
    <a-modal
      v-model="modal2Visible"
      :closable="false"
      :keyboard="false"
      :maskClosable="false"
      title="请确认账号密码"
    >
      <div style="text-align:center">
        <p>{{ `专家姓名： ${this.accountpassword.username} ` }}</p>
        <p>{{ `帐号： ${this.accountpassword.account} ` }}</p>
        <p>{{ `密码： ${this.accountpassword.password} ` }}</p>
      </div>
      <template slot="footer">
        <a-popconfirm
          title="确定记住了账号和密码？"
          ok-text="是"
          cancel-text="否"
          @confirm="confirm"
          @cancel="cancel"
        >
          <a href="#">确定</a>
        </a-popconfirm>
      </template>
    </a-modal>
    <a-modal
      :visible="freezedata"
      @ok="handleOktime"
      @cancel="handleCanceltime"
      title="请确认冻结时间"
    >
      <a-form-model ref="freezetime" :model="freezetime" :label-col="{span: 10}" :wrapper-col="{span: 10} " :rules="freezeform">
        <a-form-model-item label="解冻日期" prop="timepick">
          <a-date-picker @change="onChangefreezetime" v-model="freezetime.timepick"/>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
    <a-button type="primary" @click="addexpert()" style="margin-bottom:15px;margin-right:15px">
      添加专家
    </a-button>
    <label style="margin:5px">年度:</label>
    <a-range-picker @change="onChangeday" style="margin-bottom:15px;margin-right:15px" :format="dateFormat" />
    <a-input-search placeholder="输入您要搜索的内容" @search="onSearch" enter-button style="width:20%" v-model="search" />
    <div style="display: flex; align-items: center">
      <!-- multiple:是否支持多选；action：上传地址；method：请求方法；headers：设置上传的请求头部 -->
      <a-upload :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload" :multiple="false">
        <a-button> <a-icon type="upload" /> 选择excel文件 </a-button>
      </a-upload>
      <a-button
        type="primary"
        style="margin: 5px"
        :disabled="fileList.length === 0"
        :loading="uploading"
        @click="handleUpload"
      >
        {{ uploading ? '上传中' : '开始上传' }}
      </a-button>
      <!-- <a @click="downloadExecl">点击此处下载模版</a> -->
      <download-excel
        style="margin-left: 15px;"
        class="export-excel-wrapper"
        :data="json_data"
        :fields="json_fields"
        name="远程诊断报告导出.xls">
        <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
        <a-button type="primary" @click="exprot" :disabled="exportexcel">导出EXCEL</a-button>
      </download-excel>
    </div>
    <a-table
      :columns="columns"
      :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, rowSelection: rowSelection }"
      :row-key="record => record.argument_experts_id"
      :data-source="dataSource"
      :rowClassName="rowClassName"
      :scroll="{ x: 1800 }"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="experts_types" slot-scope="experts_types">
        <a-tag v-for="tag in experts_types" :key="tag" :value="tag" color="blue" >
          {{ tag }}
        </a-tag>
      </span>
      <template slot="operation" slot-scope="text, record">
        <!-- <a
          v-if="dataSource.length"
          @click="() => behaviormanage(record)"
        >
          <a href="javascript:;">行为管理</a>
        </a>
        <a-divider type="vertical" />
        <a
          v-if="dataSource.length"
          @click="() => evaluation(record)"
        >
          <a href="javascript:;">考核评价</a>
        </a>
        <a-divider type="vertical" /> -->
        <a
          v-if="dataSource.length"
          @click="() => details(record)"
        >
          <a href="javascript:;">详情</a>
        </a>
      </template>
    </a-table>
    <!-- <a-button type="primary" :disabled="!hasSelected" :loading="loading" @click="start">
      删除
    </a-button>
    <span style="margin-left: 8px">
      <template v-if="hasSelected">
        {{ `Selected ${selectedRowKeys.length} items` }}
      </template>
    </span> -->
    <a-modal
      :title="dialogTitle"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @cancel="handleCancel"
      v-if="visible"
    >
      <a-form-model ref="expertmessage" :model="expertmessage" :label-col="{span: 7}" :wrapper-col="{span: 16} " :rules="rules">
        <a-form-model-item label="专家姓名" prop="username" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.username"></a-input>
        </a-form-model-item>
        <a-form-model-item label="专家身份证号码" prop="card_num" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.card_num" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="专家性别" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-select v-model="expertmessage.sex">
            <a-select-option value="男">
              男
            </a-select-option>
            <a-select-option value="女">
              女
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="专家所属单位" prop="company_name" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.company_name"></a-input>
        </a-form-model-item>
        <a-form-model-item label="专家手机号码" prop="phone" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.phone" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="专家职称" prop="experts_title" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.experts_title" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="职称专业" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.title_major" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="专业资格" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.major_status" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="专家论证类别" prop="experts_types" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-select
            mode="multiple"
            style="width: 100%"
            @change="handleChangetype"
            v-model="expertmessage.experts_types"
          >
            <a-select-option v-for="item in experttype" :key="item.type_id" :value="item.type_name">
              {{ item.type_name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="专家级别" prop="experts_level" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-select
            style="width: 100%"
            @change="handleChangelevel"
            v-model="expertmessage.experts_level"
          >
            <a-select-option v-for="item in expertlevel" :key="item.experts_level_types_id" :value="item.experts_level_types_name">
              {{ item.experts_level_types_name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="创建时间" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-date-picker v-model="expertmessage.create_time"></a-date-picker>
        </a-form-model-item>
        <a-form-model-item label="相关证件图片" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-button @click="pictures()">点击添加图片</a-button>
        </a-form-model-item>
        <a-modal
          v-model="picturesvisible"
          title="图片详情"
          @ok="picturesmodel"
          okText="保存"
          cancelText="取消"
          width="40%"
        >
          <a-form-model ref="expertmessage" :model="expertmessage" :label-col="{span: 8}" :wrapper-col="{span: 16} " :rules="rules">
            <a-form-model-item label="本人证件照" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
              <a-upload
                :file-list="expertmessage.my_photo"
                :remove="handleRemovemy"
                :before-upload="beforeUploadmy"
                @preview="handlePreview"
                name="file"
                list-type="picture-card"
                @change="handleChange"
                :custom-request="(data) => {handleUploadmy(data,1)}"
              >
                <a-button> <a-icon type="plus" /> 选择图片 </a-button>
              </a-upload>
            </a-form-model-item>
            <a-form-model-item label="身份证文件" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
              <a-upload
                :file-list="expertmessage.my_card_photo"
                :remove="handleRemoveid"
                :before-upload="beforeUploadmy"
                @preview="handlePreview"
                name="file"
                list-type="picture-card"
                @change="handleChange"
                :custom-request="(data) => {handleUploadmy(data,2)}"
              >
                <a-button> <a-icon type="plus" /> 选择图片 </a-button>
              </a-upload>
            </a-form-model-item>
            <a-form-model-item label="学历证明文件" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
              <a-upload
                :file-list="expertmessage.academic_credentials"
                :remove="handleRemoveEd"
                :before-upload="beforeUploadmy"
                @preview="handlePreview"
                name="file"
                list-type="picture-card"
                @change="handleChange"
                :custom-request="(data) => {handleUploadmy(data,3)}"
              >
                <a-button> <a-icon type="plus" /> 选择图片 </a-button>
              </a-upload>
            </a-form-model-item>
            <a-form-model-item label="职称文件" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
              <a-upload
                :file-list="expertmessage.title_document"
                :remove="handleRemovejob"
                :before-upload="beforeUploadmy"
                @preview="handlePreview"
                name="file"
                list-type="picture-card"
                @change="handleChange"
                :custom-request="(data) => {handleUploadmy(data,4)}"
              >
                <a-button> <a-icon type="plus" /> 选择图片 </a-button>
              </a-upload>
            </a-form-model-item>
            <a-form-model-item label="执业资格文件" prop="" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
              <a-upload
                :file-list="expertmessage.practice_qualification_certificate"
                :remove="handleRemovequa"
                :before-upload="beforeUploadmy"
                @preview="handlePreview"
                name="file"
                list-type="picture-card"
                @change="handleChange"
                :custom-request="(data) => {handleUploadmy(data,5)}"
              >
                <a-button> <a-icon type="plus" /> 选择图片 </a-button>
              </a-upload>
            </a-form-model-item>
          </a-form-model>
        </a-modal>
        <a-form-model-item label="备注" prop="remarks" :style="{ display: 'inline-block', width: 'calc(50% - 12px)' }">
          <a-input v-model="expertmessage.remarks" ></a-input>
        </a-form-model-item>
      </a-form-model>
      <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancelimg">
        <img alt="example" style="width: 100%" :src="previewImage" />
      </a-modal>
      <template slot="footer">
        <Button type="button" class="ant-btn ant-btn-primary" @click="handleOk" :loading="confirmLoading" :disabled="confirmLoading">保存</Button>
        <Button type="button" class="ant-btn ant-btn-primary" @click="freeze" v-show="status" :disabled="!islogoff || pendingreview">{{ freezetext }}</Button>
        <Button type="button" class="ant-btn ant-btn-danger" @click="logoff" v-show="status">{{ logofftext }}</Button>
        <Button type="button" class="ant-btn" @click="handleCancel">取消</Button>
      </template>
    </a-modal>
  </page-header-wrapper>
</template>

<script>
import { getexperttype, addexpertmessage, getexperlevel, getdatatable, saveexpertmessage, statusmod, fuzzyquery, importexl } from '@/api/argumentexpert'
import XLSX from 'xlsx'
import { uploadImages } from '@/api/upload'
import { formatDate } from '@/api/date.js'

const delay = (function () {
 let timer = 0
 return function (callback, ms) {
  clearTimeout(timer)
  timer = setTimeout(callback, ms)
 }
})()
const columns = [
  {
    title: '姓名',
    dataIndex: 'username',
    width: 125,
    align: 'center',
    fixed: 'left',
    scopedSlots: { customRender: 'name' }
  },
  {
    title: '手机号码',
    dataIndex: 'phone',
    width: 150
  },
  {
    title: '身份证号',
    dataIndex: 'card_num',
    width: 175
  },
  {
    title: '专家职称',
    dataIndex: 'experts_title',
    width: 125
  },
  {
    title: '所属单位',
    dataIndex: 'company_name'
  },
  {
    title: '专家级别',
    dataIndex: 'experts_level',
    width: 125
  },
  {
    title: '专家类别',
    dataIndex: 'experts_types',
    scopedSlots: { customRender: 'experts_types' }
  },
  {
    title: '状态',
    dataIndex: 'experts_status',
    width: 90
  },
  {
    title: '操作',
    dataIndex: 'operation',
    fixed: 'right',
    align: 'center',
    width: 240,
    scopedSlots: { customRender: 'operation' }
  }
]
function getBase64 (file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => resolve(reader.result)
    reader.onerror = error => reject(error)
  })
}

export default {
  // inject: ['reload'],
  data () {
    return {
      headers: {
        authorization: 'authorization-text'
      },
      json_fields: {
        '姓名': 'username', // 常规字段
        '手机号': 'phone', // 支持嵌套属性
        '身份证号': 'card_num', // 支持嵌套属性
        '所属单位': 'company_name',
        '专家职称': 'experts_title',
        '职称专业': 'title_major',
        '专业资格': 'major_status',
        '专家类别': 'experts_types',
        '专家级别': 'experts_level',
        '备注说明': 'remarks',
        '创建时间':'create_time'
      },
      json_data: [],
      json_meta: [
        [
          {
            ' key ': ' charset ',
            ' value ': ' utf- 8 '
          }
        ]
      ],
      previewVisible: false,
      previewImage: '',
      fileList: [], // excel表的属性
      uploading: false,
      freezedata: false,
      freezetime: {},
      freezeday: '',
      mask: false,
      dateFormat: 'YYYY/MM/DD',
      status: Boolean, // 判断新增还是修改
      dialogTitle: undefined,
      maskClosable: false,
      isfreeze: false, // 判断是否冻结
      freezetext: '冻结',
      islogoff: false, // 判断是否注销
      logofftext: '',
      expertstatus: '',
      pendingreview: false, // 是否为待审核
      visible: false,
      modal2Visible: false,
      searchName: '',
      confirmLoading: false,
      expertmessage: {
        my_photo: [],
        my_card_photo: [],
        academic_credentials: [],
        title_document: [],
        practice_qualification_certificate: []
      },
      picturesvisible: false,//专家图片详情
      sendexperttype: '', // 传递专家类型
      sendexpertlevel: '', // 传递专家级别
      accountpassword: '',
      dataSource: [], // 表格数据
      rules: {
        username: [
          { required: true, message: '内容不可为空', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '内容不可为空', trigger: 'blur' },
          { min: 11, max: 11, message: '长度在 11 个字符' }
        ],
        card_num: [
          { required: true, message: '内容不可为空', trigger: 'blur' },
          { min: 18, max: 18, message: '长度在 18 个字符' }
        ],
        experts_title: [
          { required: true, message: '内容不可为空', trigger: 'blur' }
        ],
        company_name: [
          { required: true, message: '内容不可为空', trigger: 'blur' }
        ],
        experts_types: [
          { required: true, message: '内容不可为空', trigger: 'blur' }
        ],
        experts_level: [
          { required: true, message: '内容不可为空', trigger: 'blur' }
        ]
      },
      freezeform: {
        timepick: [
          { required: true, message: '内容不可为空' }
        ]
      },
      search: '',
      experttype: '', // 专家类型
      expertlevel: '', // 专家级别
      datestring: '',
      selectedRowKeys: [], // Check here to configure the default column
      rowSelection: [],
      exportexcel: true,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true,
        pageSizeOptions: ['10', '20', '30', '50']
      }, // 分页属性
      loading: false,
      columns
    }
  },
  mounted () {
    // this.fetch()
  },
  created () {
    console.log(this.expertmessage)
    this.getdata()
  },
  watch: {
    search: function (newVal, oldVal) {
      delay(() => {
        this.onSearch(newVal)
      }, 1000)
    }
  },
  computed: {
    hasSelected () {
      return this.selectedRowKeys.length > 0
    }
  },
  methods: {
    // 查看图片
    async handlePreview (file) {
      if (!file.url && !file.preview) {
        file.preview = await getBase64(file.originFileObj)
      }
      this.previewImage = file.url || file.preview
      this.previewVisible = true
    },
    handleCancelimg () {
      this.previewVisible = false
    },
    handleChange (file) {
      // this.fileListmy = fileList
      console.log(file)
    },
    handleRemove (file) {
      const index = this.fileList.indexOf(file)
      const newFileList = this.fileList.slice()
      newFileList.splice(index, 1)
      this.fileList = newFileList
    },
    // 模态框图片移除功能
    handleRemovemy (file) {
      const index = this.expertmessage.my_photo.indexOf(file)
      const newFileList = this.expertmessage.my_photo.slice()
      newFileList.splice(index, 1)
      this.expertmessage.my_photo = newFileList
    },
    handleRemoveid (file) {
      const index = this.expertmessage.my_card_photo.indexOf(file)
      const newFileList = this.expertmessage.my_card_photo.slice()
      newFileList.splice(index, 1)
      this.expertmessage.my_card_photo = newFileList
    },
    handleRemoveEd (file) {
      const index = this.expertmessage.academic_credentials.indexOf(file)
      const newFileList = this.expertmessage.academic_credentials.slice()
      newFileList.splice(index, 1)
      this.expertmessage.academic_credentials = newFileList
    },
    handleRemovejob (file) {
      const index = this.expertmessage.title_document.indexOf(file)
      const newFileList = this.expertmessage.title_document.slice()
      newFileList.splice(index, 1)
      this.expertmessage.title_document = newFileList
    },
    handleRemovequa (file) {
      const index = this.expertmessage.practice_qualification_certificate.indexOf(file)
      const newFileList = this.expertmessage.practice_qualification_certificate.slice()
      newFileList.splice(index, 1)
      this.expertmessage.practice_qualification_certificate = newFileList
    },
    // 判断图片格式和大小
    beforeUploadmy (file) {
      console.log(file)
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg'
      if (!isJpgOrPng) {
        // this.$message.error('You can only upload JPG file!')
        this.$message.error('您只能上传 JPG 文件!')
      }
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        // this.$message.error('Image must smaller than 2MB!')
        this.$message.error('图片必须小于 2MB!')
      }
      return isJpgOrPng && isLt2M
    },
    // 自定义图片上传
    handleUploadmy (data, value) {
      console.log(data, value)
      const file = {
        file_id:'1',
        uid: '1',
        // thumbUrl: res.result[0].url,
        name: '1',
        status: 'uploading',
        url: ''
      }
      console.log(file)
      var fd = new FormData()
      console.log(data.file)
      fd.append('file[0]', data.file)
      console.log(fd)
      uploadImages(fd).then(res => {
        if (res.code === 200) {
          this.$notification.success({
            message: '上传成功'
          })
          console.log(res)
          file.uid = res.result[0].file_id
          file.name = res.result[0].file_id
          file.status = 'done'
          file.url = res.result[0].url
          file.file_id = res.result[0].file_id
          if (value === 1) {
            this.expertmessage.my_photo.push(file)
            console.log(this.expertmessage)
          } else if (value === 2) {
            this.expertmessage.my_card_photo.push(file)
          } else if (value === 3) {
            this.expertmessage.academic_credentials.push(file)
          } else if (value === 4) {
            this.expertmessage.title_document.push(file)
          } else if (value === 5) {
            this.expertmessage.practice_qualification_certificate.push(file)
          }
        } else {
          this.$notification.error({
            message: res.code,
            description: res.message
          })
        }
      }).catch(err => {
        this.$notification.error({
          message: err.code,
          description: err.message
        })
        console.log(err)
      })
    },
    beforeUpload (file) {
      this.fileList = [...this.fileList, file]
      return false
    },
    exprot () {
      this.json_data = this.rowSelection
    },
    handleUpload () {
      // this.fileData = files // 保存当前选择文件
      var that = this
      var type = this.fileList[0].name.split('.')
      if (!this.fileList[0]) {
        // 如果没有文件
        return false
      } else if (type[type.length - 1] !== 'xlsx' && type[type.length - 1] !== 'xls') {
        this.$message.error('上传格式不正确，请上传xls或者xlsx格式')
        return false
      }
      const fileReader = new FileReader()
      // 如果为原生 input 则应是 files[0]
      fileReader.readAsBinaryString(this.fileList[0])
      fileReader.onload = ev => { // 异步执行
        try {
          const data = ev.target.result
          const workbook = XLSX.read(data, {
              type: 'binary'
          })
          console.log(workbook.SheetNames)
          const wsname = workbook.SheetNames[0] // 取第一张表
          const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]) // 生成json表格内容
          console.log(ws)
          var fdexl = new FormData()
          fdexl.append('import_data', ws)
          importexl(ws).then(res => {
            that.getdata()
            this.$message.success('上传成功')
          })
          // that.uploadData = [] // 清空接收数据
          // for (var i = 0; i < ws.length; i++) {
          //   var sheetData = {
          //       // 键名为绑定 el 表格的关键字，值则是 ws[i][对应表头名]
          //       sort: i + 1,
          //       name: ws[i]['姓名'],
          //       phone: ws[i]['手机号']
          //   }
          //   that.uploadData.push(sheetData)
          //   console.log(sheetData)
          // }
        } catch (ev) {
          return false
        }
      }
      setTimeout(() => {
        this.fileList = []
      }, 1000)
      // window.onload()
      // this.reload()
      this.getdata()
    },
    onChangeday (date, dateString) {
      console.log(date, dateString)
      this.datestring = dateString
      this.onSearch()
    },
    confirm () {
      this.$message.success('添加成功')
      this.modal2Visible = false
      this.visible = false
    },
    cancel () {
      this.$message.error('请确认您的帐号密码')
    },
    getdata () {
      var fd = new FormData()
      fd.append('per_page', this.pagination.pageSize)
      fd.append('current_page', this.pagination.current)
      fd.append('experts_status', 'all')
      // console.log(JSON.stringify(fd))
      this.loading = true
      getdatatable(fd).then(res => {
        this.dataSource = res.result.data
        // console.log(res.result.data)
        Object.assign(this.pagination, { 'pageSize': Number(res.result.per_page), 'total': res.result.total, 'current': res.result.current_page })
        // console.log(this.pagination)
        this.loading = false
        // setTimeout(() => {
        //   this.loading = false
        // }, 1000)
      })
    },
    handleTableChange (pagination) {
      console.log(pagination)
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      if (this.search) {
        this.onSearch()
      } else {
        this.getdata()
      }
    },
    rowClassName () {
      return 'rowClass'
    },
    onSearch (value) {
      // console.log((new Date(this.datestring[0])).getTime() / 1000)
      var searchmes = new FormData()
      searchmes.append('query', this.search)
      searchmes.append('per_page', this.pagination.pageSize)
      searchmes.append('current_page', this.pagination.current)
      if (this.datestring[0]) {
        searchmes.append('start_date', (new Date(this.datestring[0])).getTime() / 1000)
        searchmes.append('end_date', (new Date(this.datestring[1])).getTime() / 1000)
      }
      this.loading = true
      fuzzyquery(searchmes).then(res => {
        this.dataSource = res.result.data
        Object.assign(this.pagination, { 'pageSize': Number(res.result.per_page), 'total': res.result.total, 'current': res.result.current_page })
        this.loading = false
        // setTimeout(() => {
        //   this.loading = false
        // }, 500)
      })
    },
    handleChangetype (value) {
      this.sendexperttype = value
      this.sendexperttype.map(String)
    },
    handleChangelevel (value) {
      this.sendexpertlevel = value
    },
    onChangefreezetime (date, datastring) {
      console.log(date, datastring)
      this.freezeday = datastring
    },
    // 确定冻结时间
    handleOktime () {
      this.$refs.freezetime.validate(valid => {
        if (!valid) {
          return false
        } else {
          var freezemod = new FormData()
          freezemod.append('all_user_ids', this.expertmessage.user_id)
          freezemod.append('unfreeze_time', (new Date(this.freezeday)).getTime() / 1000)
          freezemod.append('operation', 'freeze')
          statusmod(freezemod).then(res => {
            if (res.message === 'success') {
              this.$message.success('冻结成功')
              this.visible = false
              this.freezedata = false
              this.freezetime = {}
            } else {
              this.$message.error(res.message)
            }
          })
          setTimeout(() => {
            this.getdata()
          }, 500)
        }
      })
    },
    handleCanceltime () {
      this.freezedata = false
      this.visible = true
    },
    // 冻结
    freeze () {
      if (this.isfreeze) {
        this.freezedata = true
        this.visible = false
      } else {
        var unfreezemod = new FormData()
        unfreezemod.append('all_user_ids', this.expertmessage.user_id)
        unfreezemod.append('operation', 'unfreeze')
        statusmod(unfreezemod).then(res => {
          if (res.message === 'success') {
            this.$message.success('解冻成功')
            this.visible = false
          } else {
            this.$message.error(res.message)
          }
        })
        setTimeout(() => {
          this.getdata()
        }, 2000)
      }
    },
    // 注销
    logoff () {
      if (this.islogoff) {
        var logoffmod = new FormData()
        logoffmod.append('all_user_ids', this.expertmessage.user_id)
        logoffmod.append('operation', 'logoff')
        statusmod(logoffmod).then(res => {
          if (res.message === 'success') {
            this.$message.success('注销成功')
            this.visible = false
          } else {
            this.$message.error(res.message)
          }
        })
        setTimeout(() => {
          this.getdata()
        }, 2000)
      } else {
        var unlogoffmod = new FormData()
        unlogoffmod.append('all_user_ids', this.expertmessage.user_id)
        unlogoffmod.append('operation', 'recovery')
        statusmod(unlogoffmod).then(res => {
          if (res.message === 'success') {
            this.$message.success('恢复成功成功')
            this.visible = false
          } else {
            this.$message.error(res.message)
          }
        })
        setTimeout(() => {
          this.getdata()
        }, 2000)
      }
    },
    // 模态框保存
    handleOk () {
      this.$refs.expertmessage.validate(valid => {
        console.log(this.expertmessage)
        if (!valid) {
          return false
        } else {
          this.confirmLoading = true
          if (!this.status) {
            var request = {
              'username': this.expertmessage.username,
              'card_num': this.expertmessage.card_num,
              'sex': this.expertmessage.sex,
              'company_name': this.expertmessage.company_name,
              'remarks': this.expertmessage.remarks,
              'phone': this.expertmessage.phone,
              'experts_title': this.expertmessage.experts_title,
              'title_major': this.expertmessage.title_major,
              'major_status': this.expertmessage.major_status,
              'experts_types': this.expertmessage.experts_types,
              'experts_level': this.expertmessage.experts_level,
              'my_photo': this.expertmessage.my_photo,
              'my_card_photo': this.expertmessage.my_card_photo,
              'academic_credentials': this.expertmessage.academic_credentials,
              'title_document': this.expertmessage.title_document,
              'practice_qualification_certificate': this.expertmessage.practice_qualification_certificate,
              'create_time':this.expertmessage.create_time
            }
            addexpertmessage(request).then(res => {
              if (res.message === 'success') {
                this.accountpassword = res.result
                this.modal2Visible = true
                this.handleCancel()
              } else {
                this.$message.error(res.message)
              }
            })
          } else {
            var modmess = {
              'username': this.expertmessage.username,
              'card_num': this.expertmessage.card_num,
              'sex': this.expertmessage.sex,
              'company_name': this.expertmessage.company_name,
              'remarks': this.expertmessage.remarks,
              'phone': this.expertmessage.phone,
              'experts_title': this.expertmessage.experts_title,
              'title_major': this.expertmessage.title_major,
              'major_status': this.expertmessage.major_status,
              'experts_types': this.expertmessage.experts_types,
              'experts_level': this.expertmessage.experts_level,
              'my_photo': this.expertmessage.my_photo,
              'my_card_photo': this.expertmessage.my_card_photo,
              'academic_credentials': this.expertmessage.academic_credentials,
              'title_document': this.expertmessage.title_document,
              'practice_qualification_certificate': this.expertmessage.practice_qualification_certificate,
              'user_id': this.expertmessage.user_id,
              'create_time':this.expertmessage.create_time
            }
            saveexpertmessage(modmess).then(res => {
              if (res.message === 'success') {
                this.visible = false
                this.$message.success('修改成功')
              } else {
                this.$message.error(res.message)
              }
            })
          }
          setTimeout(() => {
            this.confirmLoading = false
            this.getdata()
          }, 1000)
        }
      })
    },
    handleCancel () {
      this.visible = false
      this.expertmessage = {
        my_photo: [],
        my_card_photo: [],
        academic_credentials: [],
        title_document: [],
        practice_qualification_certificate: []
      }
    },
    addexpert () {
      this.status = false
      this.visible = true
      this.dialogTitle = '新增专家'
      var formdata = new FormData()
      formdata.append('type_kinds', '1')
      // formdata.append('flag', '新增专家')
      getexperttype(formdata).then(res => {
        this.experttype = res.result.data
      })
      getexperlevel(formdata).then(res => {
        this.expertlevel = res.result.data
      })
    },
    behaviormanage () {
      // const data = [...this.data]
      // this.data = data.filter(item => item.key !== key)
      console.log(1)
    },
    evaluation () {

    },
    // 查看专家详情
    details (value) {
      console.log(value)
      console.log(value.my_photo)
      console.log(value.experts_status)
      if (value.experts_status === '正常') {
        this.pendingreview = false
        this.freezetext = '冻结'
        this.isfreeze = true
        this.logofftext = '注销'
        this.islogoff = true
      } else if (value.experts_status === '待审核') {
        this.pendingreview = true
        this.freezetext = '冻结'
        this.isfreeze = true
        this.logofftext = '注销'
        this.islogoff = true
      } else if (value.experts_status === '已拒绝') {
        this.pendingreview = true
        this.freezetext = '冻结'
        this.isfreeze = true
        this.logofftext = '注销'
        this.islogoff = true
      } else if (value.experts_status === '冻结') {
        this.pendingreview = false
        this.freezetext = '解冻'
        this.isfreeze = false
        this.logofftext = '注销'
        this.islogoff = true
      } else if (value.experts_status === '注销') {
        this.pendingreview = false
        this.freezetext = '冻结'
        this.isfreeze = false
        this.logofftext = '恢复'
        this.islogoff = false
      }
      this.status = true
      this.dialogTitle = '专家详情'
      this.expertmessage = JSON.parse(JSON.stringify(value))
      console.log(this.expertmessage.create_time)
      this.visible = true
      console.log(this.expertmessage)
      // this.expertmessage.my_photo = 
      var formdata = new FormData()
      formdata.append('type_kinds', '1')
      getexperttype(formdata).then(res => {
        this.experttype = res.result.data
      })
      getexperlevel(formdata).then(res => {
        this.expertlevel = res.result.data
      })
    },
    // start () {
    //   this.loading = true
    //   // ajax request after empty completing
    //   setTimeout(() => {
    //     this.loading = false
    //     this.selectedRowKeys = []
    //   }, 1000)
    // },
    onSelectChange (selectedRowKeys, rowSelection) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      console.log(rowSelection)
      this.selectedRowKeys = selectedRowKeys
      this.rowSelection = rowSelection
      if (this.rowSelection.length) {
        this.exportexcel = false
      } else {
        this.exportexcel = true
      }
    },
    //查看专家图片详情
    pictures () {
      this.picturesvisible = true
    },
    //专家图片详情确认
    picturesmodel () {
      this.$refs.expertmessage.validate(valid => {
        console.log(this.expertmessage)
        if (!valid) {
          return false
        } else {
          this.confirmLoading = true
          if (!this.status) {
            var request = {
              'username': this.expertmessage.username,
              'card_num': this.expertmessage.card_num,
              'sex': this.expertmessage.sex,
              'company_name': this.expertmessage.company_name,
              'remarks': this.expertmessage.remarks,
              'phone': this.expertmessage.phone,
              'experts_title': this.expertmessage.experts_title,
              'title_major': this.expertmessage.title_major,
              'major_status': this.expertmessage.major_status,
              'experts_types': this.expertmessage.experts_types,
              'experts_level': this.expertmessage.experts_level,
              'my_photo': this.expertmessage.my_photo,
              'my_card_photo': this.expertmessage.my_card_photo,
              'academic_credentials': this.expertmessage.academic_credentials,
              'title_document': this.expertmessage.title_document,
              'practice_qualification_certificate': this.expertmessage.practice_qualification_certificate,
              'create_time':this.expertmessage.create_time
            }
            addexpertmessage(request).then(res => {
              if (res.message === 'success') {
                this.accountpassword = res.result
                this.modal2Visible = true
                this.handleCancel()
              } else {
                this.$message.error(res.message)
              }
            })
          } else {
            var modmess = {
              'username': this.expertmessage.username,
              'card_num': this.expertmessage.card_num,
              'sex': this.expertmessage.sex,
              'company_name': this.expertmessage.company_name,
              'remarks': this.expertmessage.remarks,
              'phone': this.expertmessage.phone,
              'experts_title': this.expertmessage.experts_title,
              'title_major': this.expertmessage.title_major,
              'major_status': this.expertmessage.major_status,
              'experts_types': this.expertmessage.experts_types,
              'experts_level': this.expertmessage.experts_level,
              'my_photo': this.expertmessage.my_photo,
              'my_card_photo': this.expertmessage.my_card_photo,
              'academic_credentials': this.expertmessage.academic_credentials,
              'title_document': this.expertmessage.title_document,
              'practice_qualification_certificate': this.expertmessage.practice_qualification_certificate,
              'user_id': this.expertmessage.user_id,
              'create_time':this.expertmessage.create_time
            }
            saveexpertmessage(modmess).then(res => {
              if (res.message === 'success') {
                this.visible = true
                this.$message.success('修改成功')
              } else {
                this.$message.error(res.message)
              }
            })
          }
          setTimeout(() => {
            this.confirmLoading = false
            this.getdata()
          }, 1000)
        }
      })
      this.picturesvisible = false
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .components-input-demo-size .ant-input {
  width: 200px;
  float: right;
}
/deep/ .rowClass{
  background-color: #fff;
}
/deep/ .ant-modal-content{
  width: 180%;
  left: -36%;
}
</style>
